package com.bxl.netty.rpc.register.server.service;


import com.bxl.netty.rpc.common.message.MsgResponseContent;
import com.bxl.netty.rpc.common.message.PackageMsg;
import com.bxl.netty.rpc.common.message.RegisterContent;
import com.bxl.netty.rpc.register.server.RegisterServerContext;
import com.bxl.netty.rpc.register.server.service.impl.GetService;
import com.bxl.netty.rpc.register.server.service.impl.HeartBeatService;
import com.bxl.netty.rpc.register.server.service.impl.NoneService;
import com.bxl.netty.rpc.register.server.service.impl.RegisterService;

/**
 * <>
 *
 * @author baixl
 * @date 2021/3/5
 */
public enum RegisterOperDefine {
    REGISTER(1, "注册", new RegisterService()), HEARTBEAT(2, "心跳", new HeartBeatService()), GET(3, "请求", new GetService()),NONE(4,"未知操作类型",new NoneService());
    private int value;
    private String desc;
    private IOperService service;

    RegisterOperDefine(int value, String desc, IOperService service) {
        this.value = value;
        this.desc = desc;
        this.service = service;
    }

    public static RegisterOperDefine getRegisterOperDefine(int value){
        RegisterOperDefine[] values = values();
        for (RegisterOperDefine registerOperDefine : values) {
            if(registerOperDefine.value == value){
                return registerOperDefine;
            }
        }
        return  RegisterOperDefine.NONE;
    }
    
    public MsgResponseContent deal(PackageMsg<RegisterContent> msg, RegisterServerContext context) {
        return new MsgResponseContent(service.deal(msg, context));
    }
}
